import java.util.*;
public class Demo15{

    static int n;
    static int N = 10;
    static int[] path = new int[N];
    static boolean[] stu = new boolean[N];
    public  static void dfs(int u){
        if(u == n){
            for(int i = 0; i < n; i++){
                System.out.print(path[i] + " ");
            }
            System.out.println();
            return;
        }
        for(int i = 1; i <= n; i++){
            if(!stu[i]){
                path[u] = i;
                stu[i] = true;
                dfs(u + 1);
                stu[i] = false;
            }

        }
    }
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        dfs(0);
    }
}